class ConHUD extends UTTeamHUD;

var const color Black, White;

function DrawEarnings (Vector2D POS, int t)
{
  local int i;
  local array<ConPRI> A;
  local ConPRI CPRI;
  local String CL;
  local Vector2D TS; 
  local bool SortDone;
  
  TS = TextSize (21,8);

  if (t==0) DrawNiceRect (POS, TS, "red"); else DrawNiceRect (POS, TS, "blue"); 
  
  // Filter BTA
  for (i = 0; i < WorldInfo.GRI.PRIArray.length; i++) {
    CPRI = ConPRI(WorldInfo.GRI.PRIArray[i]);
    if (CPRI != None) {
      if (CPRI.Team.TeamIndex == t && !CPRI.bOnlySpectator && CPRI.PlayerName != "Admin") {
        A.AddItem (CPRI);
      }
    }
  }  
  
  // Sort BTA
  SortDone = false;
  while (!SortDone && A.length > 1) {
    SortDone = true;
    for (i=0; i < A.length-1; i++) {     
      if (PlayerCompare (A[i], A[i+1])) {
        SortDone = false;
        CPRI = A[i]; A[i] = A[i+1]; A[i+1] = CPRI;        
      }
    }
  }
  
  // Display
  DrawNiceText (POS, 0, 0, "Player ("$A.Length$")", "yellow");
  DrawNiceText (POS, 9, 0, " Round", "yellow");
  DrawNiceText (POS, 18, 0, " Total", "yellow");
  for (i = 0; i < A.length && i < 7; i++) {
    CPRI = A[i];
    CL="white";
    DrawNiceText (POS, 0, i+1, CPRI.PlayerName$" - "$CPRI.ConClass, CL);
    // DrawNiceText (POS, 9, i+1, FormatNumber(CPRI.VilRoundEarnings), CL);
	DrawNiceText (POS, 18, i+1, FormatNumber(CPRI.Score), CL);
  }
}
 
function bool PlayerCompare (ConPRI P1, ConPRI P2)
{
  // local int P1_Total; 
  // local int P2_Total;
  
  // P1_Total = P1.VilRoundEarnings + P1.VilTotalEarnings;
  // P2_Total = P2.VilRoundEarnings + P2.VilTotalEarnings;
  
  if (P1.Score < P2.Score) return true;
  return false;
}

function DrawRespawnTimer(Vector2D POS)
{
	local Vector2D TS;
	local ConPRI CPRI;
	
	CPRI = ConPRI (UTOwnerPRI);
	TS = VA2D (0, 0, 440, 41);
	
	DrawNiceRect (POS, TS, "black");
	if (CPRI.bRecentlyDead) DrawNiceTextMedium (POS, 0, 0, "You may respawn in "$ConGRI (WorldInfo.GRI).ConRespawnTime$" seconds.");
	if (!CPRI.bRecentlyDead) DrawNiceTextMedium (POS, 0, 0, "You may now [Fire] to respawn!");
}


function DrawGlobalStats(Vector2D POS)
{
	local Vector2D TS;
	
	TS = TextSize (21, 2);
	
	DrawNiceRect (POS, TS, "black");
	DrawNiceText (POS, 0, 0, "Siege Phase", "yellow");
	DrawNiceText (POS, 14, 0, " Round Time", "yellow");
	DrawNiceText (POS, 0, 1, FormatNumber(ConGRI (WorldInfo.GRI).ConSiegePhase), "white");
	DrawNiceText (POS, 18, 1, FormatNumber(ConGRI (WorldInfo.GRI).RemainingRoundTime), "white");
}

function DrawActiveObjectives(Vector2D POS)
{
	local Vector2D TS;
	local int i;
	local ConObjective CO;
	local string ObjectiveType;
	local array<ConObjective> LocalObjectives;
	
	foreach WorldInfo.AllNavigationPoints(class'ConObjective', CO)
	{
		if (CO.bConComplete == false && CO.ConAssociatedStage == ConGRI (WorldInfo.GRI).ConSiegePhase)
		{
			LocalObjectives.AddItem(CO);
		}
	}
	
	TS = TextSize (21, LocalObjectives.Length + 1);
	
	DrawNiceRect (POS, TS, "black");
	DrawNiceText (POS, 0, 0, "Objectives", "yellow");
	// DrawNiceText (POS, 10, 2, "Objective Types", "yellow");	
	
	
	for (i = 0; i < LocalObjectives.Length && i < 7; i++) {
		CO = LocalObjectives[i];
	
		if (CO.ConObjectiveType == CO_Dest) ObjectiveType = "Destructible";
		if (CO.ConObjectiveType == CO_Hold) ObjectiveType = "Capture Point";
	
		DrawNiceText (POS, 0, i+1, CO.ConObjectiveName, "white");
		DrawNiceText (POS, 10, i+1, ObjectiveType, "white");
		
  }
}


function DrawHud()
{
	local Vector2D POS;
	local ConPRI CPRI;
	local ConGRI CGRI;
	
	CGRI = ConGRI (WorldInfo.GRI);
	CPRI = ConPRI (UTOwnerPRI);
	
	POS = VA2D (10, 45, 0, 0);
	DrawGlobalStats(POS);
	POS = VA2D (10, 45, 0, 38);
	DrawEarnings(POS, CPRI.Team.TeamIndex);
	POS = VA2D (10, 45, 0, 160);
	DrawEarnings(POS, 1 - CPRI.Team.TeamIndex);
	POS = VA2D (10, 45, 0, 282);
	DrawActiveObjectives(POS);
	POS = VA2D (512, 384, -220, 110);
	if (CPRI.bConDead && !CGRI.bRoundIsOver) DrawRespawnTimer(POS);
	Super.DrawHud();
	DisplayScoring();
}

// Kyle: Begin BattleTeamArena Functions.
function String FormatNumber (int Number, optional int digits=4)
{
  local String Result;
  local int i;

  Result = ""$Number;
  i = digits - Len(Result);
  while (i-->0) Result = "  "$Result;
  return Result;
}

function DrawNiceText (vector2D POS, int Col, int Line, String Text, optional String Type="white") 
{
  DrawNiceTextABS (VA2D (0, 0, POS.X+Col*9 + 6, POS.Y+Line*14 + 6), Text, Type);
}

function DrawNiceTextSmall (vector2D POS, int Col, int Line, String Text, optional String Type="white") 
{
  DrawNiceTextABSSmall (VA2D (0, 0, POS.X+Col*9 + 6, POS.Y+Line*14 + 6), Text, Type);
}

function DrawNiceTextMedium (vector2D POS, int Col, int Line, String Text, optional String Type="white") 
{
  DrawNiceTextABSMedium (VA2D (0, 0, POS.X+Col*9 + 6, POS.Y+Line*14 + 6), Text, Type);
}

function vector2D TextSize (int Cols, int Lines)
{
  return VA2D (0, 0, 12 + Cols * 9, 8 + Lines * 14);
}

function vector2D TextSizeSmall (int Cols, int Lines)
{
  return VA2D (0, 0, 12 + Cols * 9, 8 + Lines * 14);
}

function vector2D TextSizeMedium (int Cols, int Lines)
{
  return VA2D (0, 0, 12 + Cols * 9, 8 + Lines * 14);
}

function DrawNiceRect (vector2D POS, vector2D SIZE, optional string Type="yellow")
{
  if (Type=="red") Canvas.DrawColor = MakeColor (255, 0, 0, 128);
  if (Type=="blue") Canvas.DrawColor = MakeColor (0, 0, 255, 128);
  if (Type=="yellow") Canvas.DrawColor = MakeColor (192, 192, 0, 192);
  if (Type=="black") Canvas.DrawColor = MakeColor (0, 0, 0, 192);
  Canvas.SetPos (POS.X+2, POS.Y);
  Canvas.DrawRect (SIZE.X-4, 2);
  Canvas.SetPos (POS.X, POS.Y+2);
  Canvas.DrawRect (2, SIZE.Y-4);
  Canvas.SetPos (POS.X+2, POS.Y+SIZE.Y-2);
  Canvas.DrawRect (SIZE.X-4, 2);
  Canvas.SetPos (POS.X+SIZE.X-2, POS.Y+2);
  Canvas.DrawRect (2, SIZE.Y-4);
  Canvas.SetPos (POS.X+1, POS.Y+1);
  Canvas.DrawRect (1, 1);
  Canvas.SetPos (POS.X+SIZE.X-2, POS.Y+1);
  Canvas.DrawRect (1, 1);
  Canvas.SetPos (POS.X+1, POS.Y+SIZE.Y-2);
  Canvas.DrawRect (1, 1);
  Canvas.SetPos (POS.X+SIZE.X-2, POS.Y+SIZE.Y-2);
  Canvas.DrawRect (1, 1); 
  if (Type=="red") Canvas.DrawColor = MakeColor (255, 0, 0, 32);
  if (Type=="blue") Canvas.DrawColor = MakeColor (0, 0, 255, 32);
  if (Type=="yellow") Canvas.DrawColor = MakeColor (192, 192, 0, 64);
  if (Type=="black") Canvas.DrawColor = MakeColor (0, 0, 0, 96);
  Canvas.SetPos (POS.X, POS.Y+1);
  Canvas.DrawRect (1, 1);   
  Canvas.SetPos (POS.X+1, POS.Y);
  Canvas.DrawRect (1, 1);   
  Canvas.SetPos (POS.X, POS.Y+SIZE.Y-2);
  Canvas.DrawRect (1, 1);   
  Canvas.SetPos (POS.X+1, POS.Y+SIZE.Y-1);
  Canvas.DrawRect (1, 1);   
  Canvas.SetPos (POS.X+SIZE.X-1, POS.Y+1);
  Canvas.DrawRect (1, 1);   
  Canvas.SetPos (POS.X+SIZE.X-2, POS.Y);
  Canvas.DrawRect (1, 1);   
  Canvas.SetPos (POS.X+SIZE.X-1, POS.Y+SIZE.Y-2);
  Canvas.DrawRect (1, 1);   
  Canvas.SetPos (POS.X+SIZE.X-2, POS.Y+SIZE.Y-1);
  Canvas.DrawRect (1, 1);   
  Canvas.SetPos (POS.X+2, POS.Y+2);
  Canvas.DrawRect (SIZE.X-4, SIZE.Y-4);
}

function Vector2D VA2D (Int vX, int vY, int aX, int aY) // Combines (V)irtual and (A)bsolute coordinate
{
  local vector2D V;

  V.X = vX * ResolutionScaleX + aX;
   V.Y = vY * ResolutionScale + aY;
  
  return V;
}

function DrawNiceTextABS (vector2D POS, String Text, optional String Type="white") 
{
  if (Type=="white") Canvas.DrawColor = MakeColor (255, 255, 255, 255);
  if (Type=="grey") Canvas.DrawColor = MakeColor (160, 160, 160, 255);
  if (Type=="black") Canvas.DrawColor = MakeColor (80, 80, 80, 255);
  if (Type=="cyan") Canvas.DrawColor = MakeColor (0, 255, 255, 255);
  if (Type=="yellow") Canvas.DrawColor = MakeColor (255, 255, 0, 255);
  Canvas.SetPos (POS.X, POS.Y);
  //Canvas.Font = class'Engine'.static.GetLargeFont();
  //Canvas.Font = class'Engine'.static.GetMediumFont();
  //Canvas.Font = class'Engine'.static.GetSmallFont();
  Canvas.Font = class'Engine'.static.GetTinyFont();
  Canvas.DrawTextClipped (Text, false);
}

function DrawNiceTextABSSmall (vector2D POS, String Text, optional String Type="white") 
{
  if (Type=="white") Canvas.DrawColor = MakeColor (255, 255, 255, 255);
  if (Type=="grey") Canvas.DrawColor = MakeColor (160, 160, 160, 255);
  if (Type=="black") Canvas.DrawColor = MakeColor (80, 80, 80, 255);
  if (Type=="cyan") Canvas.DrawColor = MakeColor (0, 255, 255, 255);
  if (Type=="yellow") Canvas.DrawColor = MakeColor (255, 255, 0, 255);
  Canvas.SetPos (POS.X, POS.Y);
  //Canvas.Font = class'Engine'.static.GetLargeFont();
  //Canvas.Font = class'Engine'.static.GetMediumFont();
  Canvas.Font = class'Engine'.static.GetSmallFont();
  //Canvas.Font = class'Engine'.static.GetTinyFont();
  Canvas.DrawTextClipped (Text, false);
} 

function DrawNiceTextABSMedium (vector2D POS, String Text, optional String Type="white") 
{
  if (Type=="white") Canvas.DrawColor = MakeColor (255, 255, 255, 255);
  if (Type=="grey") Canvas.DrawColor = MakeColor (160, 160, 160, 255);
  if (Type=="black") Canvas.DrawColor = MakeColor (80, 80, 80, 255);
  if (Type=="cyan") Canvas.DrawColor = MakeColor (0, 255, 255, 255);
  if (Type=="yellow") Canvas.DrawColor = MakeColor (255, 255, 0, 255);
  Canvas.SetPos (POS.X, POS.Y);
  //Canvas.Font = class'Engine'.static.GetLargeFont();
  Canvas.Font = class'Engine'.static.GetMediumFont();
  //Canvas.Font = class'Engine'.static.GetSmallFont();
  //Canvas.Font = class'Engine'.static.GetTinyFont();
  Canvas.DrawTextClipped (Text, false);
} 

// Kyle: End BattleTeamArena HUD Functions.

defaultproperties
{
   Name="ConHUD"
}
